package com.wolfeyes.system.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
//import lombok.ToString;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.wolfeyes.common.annotation.Excel;

import java.io.Serializable;

/**
* @see Talk is cheap, Show me the code. -- Linus Torvalds
* @title 系统用户-实体类
* @author yanyljava
* @email yanyljava@qq.com
* @create 2022-01-12 21:24
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
//@ToString
public class SysUser implements Serializable {
	
	/**
	 * @description 串行版本标识
	 */
	private static final long serialVersionUID = -283047180787044198L;
	
	//用户id
	private Long userId;
	
	//用户名、用户账号
	@Excel(name = "登录名称")
	@NotBlank(message = "用户名不能为空")
	private String userName;
	
	//用户昵称
	@Excel(name = "用户名称")
	private String nickName;

	
	//密码
	@NotBlank(message = "密码不能为空")
	private String password;
	
	//盐加密
	private String salt;
	
	//用户邮箱
	@Excel(name = "用户邮箱")
	@Email(message = "邮箱格式有误")
	private String email;
	
	//电话号码
	//手机号码
	@Excel(name = "手机号码")
	@Pattern(regexp = "^1[3|4|5|7|8]\\d{9}$", message = "电话号码格式有错")
	private String phoneNumber;
	
	//用户性别
	@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
	private Boolean sex;
	
	//用户头像
	private String userPicture;
	
	//用户对应的角色id，为简化操作，采用1对1
	private Long roleId;
	
	//用户信息
	private String information;

	//用户的角色
	private SysRole sysRole;
	
	/** 手机号码 */
	@Excel(name = "手机号码")

	//用户头像
	private String avatar;
	
	// 爱好
	private String hobby;
	
	//帐号状态（0正常 1停用）
	@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
	private String status;

	//删除标志（0代表存在 2代表删除）
	private String delFlag;
	
	public boolean isAdmin() {
		
		return isAdmin(this.userId);
	}

	public static boolean isAdmin(Long userId) {
		
		return userId != null && 1L == userId;
	}
	
	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("userId", getUserId())
				.append("userName", getUserName())
				.append("nickName", getNickName())
				.append("email", getEmail())
				.append("phoneNumber", getPhoneNumber())
				.append("sex", getSex())
				.append("avatar", getAvatar())
				.append("password", getPassword())
				.append("salt", getSalt())
				.append("status", getStatus())
				.append("delFlag", getDelFlag())
				.toString();
	}
	
}

